# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=ogdi
pkgver=4.1.0
_testver=3.1.0
pkgrel=0
pkgdesc="Open Geographic Datastore Interface Library"
url="http://ogdi.sourceforge.net/"
arch="all"
license="MIT"
makedepends="
	expat-dev
	libtirpc-dev
	tcl-dev
	unixodbc-dev
	zlib-dev
	"
subpackages="
	$pkgname-dev
	$pkgname-odbc
	$pkgname-tcl
	"
source="
	https://downloads.sourceforge.net/project/ogdi/ogdi/$pkgver/ogdi-$pkgver.tar.gz
	https://downloads.sourceforge.net/project/ogdi/OGDI_Test_Suite/${_testver%.*}/ogdits-$_testver.tar.gz
	10-optimisation.patch
	20-external.patch
	"

build() {
	export TOPDIR=$builddir TARGET=Linux LD_LIBRARY_PATH=$TOPDIR/bin/Linux
	rm -r external
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-binconfigs \
		--with-zlib \
		--with-expat
	make -j1  # fails to find own libraries if built with more buildjobs

	# build tcl interface
	make -C ogdi/tcl_interface \
		TCL_LINKLIB="-ltcl8.6"

	# build contributions
	make -C contrib/gdal

	# build odbc drivers
	make -C ogdi/attr_driver/odbc \
		ODBC_LINKLIB="-lodbc"
}

check() {
	export TOPDIR=$builddir TARGET=Linux LD_LIBRARY_PATH=$TOPDIR/bin/Linux PATH=$PATH:$builddir/bin/Linux
	ogdi_info -u gltp:/vrf/$srcdir/ogdits-${_testver%.*}/data/vpf/vm2alv2/texash | \
		grep "Projection = \`+proj=longlat +datum=wgs84'"
}

package() {
	export TOPDIR=$builddir TARGET=Linux
	make install \
		INST_INCLUDE=$pkgdir/usr/include/ogdi \
		INST_LIB=$pkgdir/usr/lib \
		INST_BIN=$pkgdir/usr/bin

	# install gdal contribution
	make install -C contrib/gdal \
		INST_LIB=$pkgdir/usr/lib

	# install pkgconfig file
	mkdir -p $pkgdir/usr/lib/pkgconfig
	install -p -m 644 ogdi.pc $pkgdir/usr/lib/pkgconfig
}

odbc() {
	pkgdesc="ODBC driver for $pkgdesc"
	export TOPDIR=$builddir TARGET=Linux
	make install -C $builddir/ogdi/attr_driver/odbc \
		INST_LIB=$subpkgdir/usr/lib
}

tcl() {
	pkgdesc="TCL wrapper for $pkgdesc"
	export TOPDIR=$builddir TARGET=Linux
	make install -C $builddir/ogdi/tcl_interface \
		INST_LIB=$subpkgdir/usr/lib
}

sha512sums="abfc409bfa5ea2f81a90c16361fe6cdc2b2ee39775c22ceb74b13b171aa04d6d6eaffe398cae0ef91dcde8509e5cc25100eedeffdad358e090b78e118d386859  ogdi-4.1.0.tar.gz
7fbd7c165466b6bf298d3d18b33c13b6f0166c3b1efe12b7c09e77539a20076950bc89db6c4e1e411ba374ebcf81744ec0410d3a414f395bd12339a7ae0e336b  ogdits-3.1.0.tar.gz
24682c9e893e410d08bfc0a1b06196e5d0555d4b552e07662ec26433e07f44a8f99686f79a1a5ed40de71f7da838516ffc33918837a6d79f35ab2a9b380f5592  10-optimisation.patch
ca0283bd2791919bc4ae71af6ecf8d8900376fdef6b1d0808ae7d598501225c8a652e865214c43efc937e0d9514780f556100128c3dabff71a4792c8dd68380c  20-external.patch"
